/*
 * This file is part of the Android Dimensions Editor Project: http://code.google.com/p/android-dimension-editor/
 *  
 * Copyright (c) 2013 Rick Falck
 *  
 * This code is licensed under the terms of the Apache License Version 2.0.
 * You may use this code according to the license.
 *
 * The terms of the license can be found in the root directory of this project's repository as well as at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under these Licenses is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See each License for the specific language governing permissions and
 * limitations under that License.
 */
package MessageBox;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

/**
 *
 * @author Rick
 */
public class WebViewController implements Initializable {

    @FXML
    private Button mBtnClose;

    @FXML
    private WebView mWebView;

    private final Stage myStage;

    public WebViewController(Stage stage) {
        this.myStage = stage;
    }

    @Override
    public void initialize(URL fxmlFileLocation, ResourceBundle arg1) {
        this.myStage.setResizable(true);
        InputStreamReader isr = null;
        try {
            StringBuilder html = new StringBuilder();
            File f = new File("helpfiles/help.htm");
            isr = new InputStreamReader(new FileInputStream(f), "utf-8");
            int in;
            while ((in = isr.read()) > 0 ) {
                html.append((char)in);            
            }
            mWebView.getEngine().loadContent(html.toString());           
        } catch (IOException ex) {
            Logger.getLogger(WebViewController.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (isr != null) {
                try {
                    isr.close();
                } catch (IOException ex) {
                    Logger.getLogger(WebViewController.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        mWebView.getEngine().load("http://code.google.com/p/android-dimension-editor/wiki/Android_Dimensions_Editor?ts=1387521593&updated=Android_Dimensions_Editor");    

    }
}
